package com.kuang.lesson03.chat

import java.net.DatagramPacket
import java.net.DatagramSocket
import java.net.InetSocketAddress

fun main() {
    DatagramSocket(9000).use { socket ->
        while (true) {
            val msg = readLine()
            msg?.toByteArray()?.let {
                val packet = DatagramPacket(it, it.size, InetSocketAddress("127.0.0.1", 9666))
                socket.send(packet)
            }
            if ("bye" == msg) break
        }
    }
}